﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IllustratedCsharp7_ch20_Linq
{
    /*  写LINQ查询时可以使用两种形式的语法：查询语法和方法语法
     
     */
    class chapt20_3MethodSyntaxAndQuerySyntax
    {
        static void _Main()
        {
            int[] numbers = { 2, 5, 28, 31, 17, 16, 42 };

            var numsQuery = from n in numbers               //查询语法
                            where n < 20
                            select n;

            var numsMethod = numbers.Where(N => N < 20);    //方法语法

            int numsCount = (from n in numbers              //两种形式的组合
                             where n < 20
                             select n).Count();

            foreach (var x in numsQuery)
                Console.Write($"{x}, ");
            Console.WriteLine();

            foreach (var x in numsMethod)
                Console.Write($"{x}, ");
            Console.WriteLine();

            Console.Write(numsCount);
        }      
    }
}
